package com.cy.pj.goods.dao;

import com.cy.pj.goods.pojo.Goods;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class GoodsDaoImpl implements GoodsDao {
    @Autowired
    private SqlSession sqlSession;

    @Override
    public List<Goods> findAll() {
        System.out.println("GoodsDaoImpl.findAll");
        String statement = "com.cy.pj.goods.dao.GoodsDao.findAll";// namespace + id
        return sqlSession.selectList(statement);
    }

    @Override
    public int deleteById(Long id) {
        return 0;
    }

    /**
     * 一般有多个参数或者是可变参数时，这个参数要封装到map进行传递
     * @param ids
     * @return
     */
    @Override
    public int deleteObjects(Integer... ids) {
        String statement = "com.cy.pj.goods.dao.GoodsDao.deleteObjects";
        Map<String, Object> map = new HashMap<>();
        map.put("ids", ids);
        return sqlSession.delete(statement, map);
    }
}
